package csv

import (
	"encoding/csv"
	log "github.com/sirupsen/logrus"
	"os"
)

func ExportCsv(filePath string, data [][]string) (err error) {
	fp, err := os.Create(filePath) // 创建文件句柄
	defer fp.Close()

	if err != nil {
		log.Fatalf("创建文件["+filePath+"]句柄失败,%v", err)
		return
	}
	_, err = fp.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM
	if err != nil {
		return
	}
	w := csv.NewWriter(fp) //创建一个新的写入文件流

	err = w.WriteAll(data)
	if err != nil {
		return
	}
	w.Flush()
	return
}
